package com.hitown.controller.dxhd;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hitown.model.dxhd.DxhdCltsZdrcl;
import com.hitown.service.dxhd.DxhdCltsZdrclService;
import com.hitown.util.Params;
import com.hitown.util.R;
import com.hitown.util.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;
import java.util.Date;

/**
 * <p>
 * 车辆态势-重点人车辆基本信息表 前端控制器
 * </p>
 *
 * @author menu
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/dxhd-clts-zdrcl")
public class DxhdCltsZdrclController {

    @Autowired
    private DxhdCltsZdrclService dxhdCltsZdrclService;

    @CrossOrigin
    @ApiOperation(value = "分页查询")
    @RequestMapping("selectPage")
    public R selectPage(@ApiIgnore @RequestBody Params<DxhdCltsZdrcl> params){
        Page<DxhdCltsZdrcl> page = new Page<>(params.getCurrent(),params.getSize());
        QueryWrapper<DxhdCltsZdrcl> wrapper =new QueryWrapper<>();
        wrapper.select("BH","JDC_JDCHPHM","JDC_ZWPPMC","JDC_YWPPMC",
                "JDC_JDCCSYSDM","(select content from t_dictionary t where type='CSYS' and id = JDC_JDCCSYSDM) JDC_JDCCSYSMC",
                "ZDRXX_MZDM","(select content from t_dictionary t where type='MZ' and id = ZDRXX_MZDM) ZDRXX_MZMC",
                "ZDRXX_JGGJDQDM","(select content from t_dictionary t where type='GJ' and id = ZDRXX_JGGJDQDM) ZDRXX_JGGJDQMC",
                "ZDRXX_JGSSXDM","ZDRXX_XBDM","(select content from t_dictionary t where type='XB' and id = ZDRXX_XBDM) ZDRXX_XBMC",
                "ZDRXX_HYZKDM","(select content from t_dictionary t where type='HYZK' and id = ZDRXX_HYZKDM) ZDRXX_HYZKMC",
                "ZDRXX_ZZMMDM","(select content from t_dictionary t where type='ZZMM' and id = ZDRXX_ZZMMDM) ZDRXX_ZZMMMC",
                "JDC_CLXH","ZDRXX_XM","ZDRXX_GMSFHM","ZDRXX_NL","ZDRXX_XZQHDM","ZDRXX_QHNXXDZ","ZDRXX_XLDM","RYZP_MC","RYZP_DZWJWZ","CTU","CTM","UTU","UTM");
        //机动车号牌号码
        if(!StringUtils.isEmpty(params.getEntity().getJdcJdchphm())) {
            wrapper.like("JDC_JDCHPHM", params.getEntity().getJdcJdchphm());
        }
        //车辆型号
        if(!StringUtils.isEmpty(params.getEntity().getJdcClxh())) {
            wrapper.eq("JDC_CLXH", params.getEntity().getJdcClxh());
        }
        //重点人姓名
        if(!StringUtils.isEmpty(params.getEntity().getZdrxxXm())) {
            wrapper.like("ZDRXX_XM", params.getEntity().getZdrxxXm());
        }
        //重点人公民身份号码
        if(!StringUtils.isEmpty(params.getEntity().getZdrxxGmsfhm())) {
            wrapper.eq("ZDRXX_GMSFHM", params.getEntity().getZdrxxGmsfhm());
        }
        IPage<DxhdCltsZdrcl> pageVo = dxhdCltsZdrclService.page(page,wrapper);
        return R.ok().put("data",pageVo);

    }


    @ApiOperation(value = "根据id查询记录")
    @RequestMapping("getById")
    public R getById(@RequestParam String Id){
        DxhdCltsZdrcl result = dxhdCltsZdrclService.getById(Id);
        return R.ok().put("data",result);

    }

    @ApiOperation(value = "保存单条记录")
    @PostMapping("save")
    public R save(@RequestBody DxhdCltsZdrcl entit){
        Boolean result = dxhdCltsZdrclService.save(entit);
        return R.ok().put("data",result);
    }


    @ApiOperation(value = "批量保存")
    @RequestMapping("saveBatch")
    public R saveBatch(@RequestBody Collection<DxhdCltsZdrcl> entityList){
        Boolean result = dxhdCltsZdrclService.saveBatch(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 选择修改")
    @RequestMapping("updateById")
    public R updateById(@RequestBody DxhdCltsZdrcl entit){
        entit.setUtm(new Date());
//        Boolean result = dxhdCltsZdrclService.updateById(entit);
        return dxhdCltsZdrclService.updateDxhdCltsZdrcl(entit);

    }


    @ApiOperation(value = "根据ID 批量更新")
    @RequestMapping("updateBatchById")
    public R updateBatchById(@RequestBody Collection<DxhdCltsZdrcl> entityList){
        Boolean result = dxhdCltsZdrclService.updateBatchById(entityList);
        return R.ok().put("data",result);

    }

    @CrossOrigin
    @ApiOperation(value = "根据 ID 删除")
    @RequestMapping("removeById")
    public R removeById(@RequestParam String Id){
        Boolean result = dxhdCltsZdrclService.removeById(Id);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "删除（根据ID 批量删除）")
    @RequestMapping("removeByIds")
    public R removeByIds(@RequestBody Collection<String> Ids){
        Boolean result = dxhdCltsZdrclService.removeByIds(Ids);
        return R.ok().put("data",result);
    }
}

